﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using WCYCReader.Utility;
using WCYCReader.Pages;

namespace WCYCReader.UserControls
{
    public partial class FontFamilyControl : UserControl
    {
        public FontFamilyControl()
        {
            this.InitializeComponent();
            
        }

        private BookReaderPage bookReaderPage;
        public FontFamilyControl(BookReaderPage bookReaderPage)
            : this()
        {
            this.bookReaderPage = bookReaderPage;
            TextBlock fontText = this.FontText;
            int valueFromSettings = (int)SettingHelper.GetValueFromSettings("BookReader_fontSize");
            fontText.Text = valueFromSettings.ToString();
            int num = int.Parse(this.FontText.Text);
            if (num != 46)
            {
                this.FontPlus.Source = new BitmapImage(new Uri("/Resource/Images/TPlus.png", UriKind.Relative));
            }
            else
            {
                this.FontPlus.Source = new BitmapImage(new Uri("/Resource/Images/TPlus2.png", UriKind.Relative));
            }
            if (num == 20)
            {
                this.FontMinus.Source = new BitmapImage(new Uri("/Resource/Images/TMinus2.png", UriKind.Relative));
                return;
            }
            this.FontMinus.Source = new BitmapImage(new Uri("/Resource/Images/TMinus.png", UriKind.Relative));
        }

        private void FontMinus_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            int num = int.Parse(this.FontText.Text);
            if (num - 2 >= 20)
            {
                this.FontText.Text = (num - 2).ToString();
                //this.PopupFontPanel(num - 2);
                this.bookReaderPage.BookReader_FontMenu(num + 2);
                this.FontPlus.Source = new BitmapImage(new Uri("/Resource/Images/TPlus.png", UriKind.Relative));
                if (num - 2 == 20)
                {
                    this.FontMinus.Source = new BitmapImage(new Uri("/Resource/Images/TMinus2.png", UriKind.Relative));
                    return;
                }
                this.FontMinus.Source = new BitmapImage(new Uri("/Resource/Images/TMinus.png", UriKind.Relative));
            }
        }

        private void FontPlus_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            int num = int.Parse(this.FontText.Text);
            if (num + 2 <= 46)
            {
                this.FontText.Text = (num + 2).ToString();
                //this.PopupFontPanel(num + 2);
                this.bookReaderPage.BookReader_FontMenu(num + 2);
                this.FontMinus.Source = new BitmapImage(new Uri("/Resource/Images/TMinus.png", UriKind.Relative));
                if (num + 2 == 46)
                {
                    this.FontPlus.Source = new BitmapImage(new Uri("/Resource/Images/TPlus2.png", UriKind.Relative));
                    return;
                }
                this.FontPlus.Source = new BitmapImage(new Uri("/Resource/Images/TPlus.png", UriKind.Relative));
            }
        }

    }
}
